//
//  TopupIntegralViewController.m
//  PrintPort
//
//  Created by 华谕 on 2017/11/16.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "TopupIntegralViewController.h"
#import "AddCarViewController.h"
#import "WebHelpViewController.h"
#import "SYPasswordView.h"
#import "RetrievePasswordViewController.h"
#import "BuyBackPasswordViewController.h"
#import "BankModel.h"

static NSString *cellPath = @"topupCell";
@interface TopupIntegralViewController ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource,PayPassWordDelegate>
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)SYPasswordView *pasView;
@property (nonatomic, strong)UIView *payPassView;
@property (nonatomic, assign)NSInteger closeType;
@property (nonatomic, strong)UIView *blackView;
@property (nonatomic, strong)UIView *backView;
@property (nonatomic, strong)UITextField *moneyField;
@property (nonatomic, strong)UILabel *proportLab;
@property (nonatomic, strong)UILabel *nowTxLab;
@property (nonatomic, strong)UIView *closeView;
@property (nonatomic, strong)UIImageView *bankImgView;
@property (nonatomic, strong)UILabel *bankLab;
@property (nonatomic, strong)NSArray *carAry;
@property (nonatomic, strong)NSDictionary *bankDic;
@property (nonatomic, assign)BOOL isPay;
@property (nonatomic, assign)BOOL isCan;
@property (nonatomic, strong)BankModel *bankModel;


@end

@implementation TopupIntegralViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self requestBankCarList];
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(Successnotice:) name:@"PaySuccess" object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PaySuccess" object:nil];
}

- (void)Successnotice:(NSNotification *)center
{
    if (!_isPay)
    {
        _isPay = YES;
        [self.navigationController popViewControllerAnimated:YES];
        
    }
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    _closeType = 0;
    _bankDic = @{@"1002":@"gongsh",@"1005":@"nongh",@"1026":@"zhongguoy",@"1003":@"jianha",@"1001":@"zhaos",@"1066":@"youzheng",@"1020":@"jiaot",@"1004":@"puf",@"1006":@"mins",@"1009":@"xingy",@"1010":@"pinganyh",@"1021":@"zhongx",@"1025":@"huax",@"1027":@"guangf",@"1022":@"guangd",@"1032":@"beij",@"1056":@"ningb"};
    [self creatUI];
    [self requestSystemConfig];
    if (_isHuiGou)
    {
        [self requestUserWallet];
    }
}

- (void)creatUI
{
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = BacksColor;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"充值";
    
    if (_isHuiGou)
    {
        self.navigationItem.title = @"回购";
        
    }
    self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT)];
    _backView.backgroundColor = BacksColor;
    [self.view addSubview:_backView];
    
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 95*displaywidth)];
    topView.backgroundColor = [UIColor whiteColor];
    [_backView addSubview:topView];
    
    UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, 80*displaywidth, 44*displaywidth) Font:13.0 Text:@"金额（￥）" Color:RGB(77, 77, 77)];
    [topView addSubview:titLab];
    UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(100*displaywidth, 10*displaywidth, SCREEN_WIDTH-115*displaywidth, 44*displaywidth) placeholder:@"请填写充值金额" passWord:NO leftImageView:nil rightImageView:nil Font:13.0];
    [textfield setValue:RGB(179, 179, 179) forKeyPath:@"_placeholderLabel.textColor"];
    textfield.textColor = RGB(77, 77, 77);
    textfield.delegate = self;
    textfield.textAlignment = NSTextAlignmentLeft;
    textfield.keyboardType = UIKeyboardTypeDecimalPad;
    [topView addSubview:textfield];
    _moneyField = textfield;
    UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(0, 64*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
    line1.backgroundColor = LinesColor;
    [topView addSubview:line1];
    
    self.proportLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 65*displaywidth, 140*displaywidth, 30*displaywidth) Font:10.0 Text:@"兑换比率 1：2" Color:RGB(77, 77, 77)];
    [topView addSubview:_proportLab];
    self.nowTxLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH/2 , 65*displaywidth,SCREEN_WIDTH/2- 15*displaywidth, 30*displaywidth) Font:10.0 Text:@"当前可提现：300积分" Color:RGB(77, 77, 77)];
    [topView addSubview:_nowTxLab];
    _nowTxLab.hidden = YES;
    CGFloat H = 160*displaywidth;
    if (_isHuiGou)
    {
        H = 100*displaywidth;
        _nowTxLab.hidden = NO;
        
    }
    self.closeView = [[UIView alloc] initWithFrame:CGRectMake(0, 130*displaywidth, SCREEN_WIDTH, H)];
    _closeView.backgroundColor = [UIColor whiteColor];
    [_backView addSubview:_closeView];
    UILabel *secondTitLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, 80*displaywidth, 39*displaywidth) Font:13.0 Text:@"支付方式" Color:RGB(77, 77, 77)];
    [_closeView addSubview:secondTitLab];
    NSArray *imgAry = @[@"weixin",@"alipay"];
    NSArray *nameAry = @[@"微信支付",@"支付宝"];
    //  @"yinhangk"  @"银行卡支付" ,@"nextimg"
    NSArray *rightImgAry = @[@"yuand",@"xuankuang"];
    if (_isHuiGou)
    {
        secondTitLab.text = @"提现方式";
        imgAry = @[@"yinhangk"];
        nameAry = @[@"银行卡"];
        rightImgAry = @[@"nextimg"];
    }
    
    for (int i = 0; i < imgAry.count; i++)
    {
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(30*displaywidth, 60*displaywidth*i+55*displaywidth, 30*displaywidth, 30*displaywidth) ImageName:imgAry[i]];
        imgView.contentMode = UIViewContentModeScaleAspectFit;
        [_closeView addSubview:imgView];
        UILabel *nameLabel = [ZCControl createLabelWithFrame:CGRectMake(95*displaywidth, 60*displaywidth*i+55*displaywidth, SCREEN_WIDTH-130*displaywidth, 30*displaywidth) Font:13.0 Text:nameAry[i] Color:RGB(77, 77, 77)];
        [_closeView addSubview:nameLabel];
        UIImageView *imageView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-35*displaywidth, 60*displaywidth*i+62.5*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:rightImgAry[i]];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.tag = 500 + i;
        [_closeView addSubview:imageView];
        UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake(0, 40*displaywidth+i*60*displaywidth, SCREEN_WIDTH, 60*displaywidth) ImageName:nil Target:self Action:@selector(closeTypeAction:) Title:nil Font:12.0];
        btn.backgroundColor = [UIColor clearColor];
        btn.tag = 100 + i;
        [_closeView addSubview:btn];
        UIView *lineview11 = [[UIView alloc] initWithFrame:CGRectMake(0, 39*displaywidth+i*60*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineview11.backgroundColor = LinesColor;
        [_closeView addSubview:lineview11];
        if (_isHuiGou)
        {
            _bankImgView = imgView;
            _bankLab = nameLabel;
        }
        else
        {
            
        }
    }
    NSString *agreeStr = @"《印港充值协议》";
    if (_isHuiGou)
    {
        agreeStr = @"《印港回购协议》";
    }
    UIButton *agreement = [ZCControl createButtonWithFrame:CGRectMake(30*displaywidth, 155*displaywidth+H, SCREEN_WIDTH-60*displaywidth, 20*displaywidth) ImageName:@"gouxuandaik" Target:self Action:@selector(agreementAction) Title:@"《印港充值协议》" Font:12.0];
    [agreement setTitleColor:RGB(255, 111, 25) forState:UIControlStateNormal];
    [_backView addSubview:agreement];
    
    UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(60*displaywidth , 195*displaywidth+H, SCREEN_WIDTH-120*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(pushBtnAction) Title:@"确认" Font:15.0];
    [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    soureBtn.backgroundColor = ThemeColor;
    [soureBtn.layer setMasksToBounds:YES];
    [soureBtn.layer setCornerRadius:5*displaywidth];
    [self.view addSubview:soureBtn];
    
    self.blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _blackView.backgroundColor = RGBA(0, 0, 0, 0.5);
    _blackView.hidden = YES;
    [sharedDelegate.window addSubview:_blackView];
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(50*displaywidth, SCREEN_HEIGHT/2-80*displaywidth, SCREEN_WIDTH-100*displaywidth, 100*displaywidth) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    //    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = [UIColor whiteColor];
    _tableview.layer.cornerRadius = 10;
    _tableview.layer.masksToBounds = YES;
    [_blackView addSubview:_tableview];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return _carAry.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_carAry.count > 0)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        BankModel *model = _carAry[indexPath.row];
        NSString *backImg = @"zhongguoy";
        if ([_bankDic.allKeys containsObject:model.bankId])
        {
            backImg = _bankDic[model.bankId];
        }
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(20*displaywidth, 15*displaywidth, 20*displaywidth, 20*displaywidth) ImageName:backImg];
        imgView.contentMode = UIViewContentModeScaleAspectFill;
        [cell.contentView addSubview:imgView];
        NSInteger lenth = model.bankcard.length;
        NSString *carNum = @"0000";
        if (lenth > 4)
        {
            carNum = [model.bankcard substringFromIndex:lenth-4];
        }
        UILabel *namelab = [ZCControl createLabelWithFrame:CGRectMake(45*displaywidth, 10*displaywidth, SCREEN_WIDTH-180*displaywidth, 30*displaywidth) Font:13.0 Text:[NSString stringWithFormat:@"%@ %@ (%@)",model.bankName,model.cardType,carNum] Color:RGB(77, 77, 77)];
        [cell.contentView addSubview:namelab];
        
    }
    
    
    return cell;
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    BankModel *model = _carAry[indexPath.row];
    if ([_bankDic.allKeys containsObject:model.bankId])
    {
        _bankImgView.image = [UIImage imageNamed:_bankDic[model.bankId]];
    }
    if (model.bankcard.length > 4)
    {
        NSString *carLastStr = [model.bankcard substringFromIndex:model.bankcard.length-4];
        _bankLab.text = [NSString stringWithFormat:@"%@ %@ (%@)",model.bankName,model.cardType,carLastStr];
    }
    _bankModel = model;
    _blackView.hidden = YES;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-100*displaywidth, 50*displaywidth)];
    myView.backgroundColor = [UIColor whiteColor];
    UIButton *backBtn = [ZCControl createButtonWithFrame:CGRectMake(10*displaywidth, 17.5*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:@"backimg" Target:self Action:@selector(backAction) Title:nil Font:12.0];
    backBtn.backgroundColor = [UIColor clearColor];
    [myView addSubview:backBtn];
    UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(35*displaywidth, 10*displaywidth, SCREEN_WIDTH-170*displaywidth, 30*displaywidth) Font:15.0 Text:@"选择银行卡" Color:RGB(77, 77, 77)];
    titlab.textAlignment = NSTextAlignmentCenter;
    [myView addSubview:titlab];
    UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 49*displaywidth, SCREEN_WIDTH-100*displaywidth, 1*displayheight)];
    lineview.backgroundColor = LinesColor;
    [myView addSubview:lineview];
    return myView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50*displaywidth;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50*displaywidth;
}


- (void)agreementAction
{
    WebHelpViewController *vc = [[WebHelpViewController alloc] init];
    vc.titleStr = @"充值协议";
    vc.typeID = 2;
    if (_isHuiGou)
    {
        vc.titleStr = @"回购协议";
        vc.typeID = 3;
        
    }
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)closeTypeAction:(UIButton *)btn
{
    [self.view endEditing:YES];
    NSInteger index = btn.tag - 100;
    NSString *aImg = @"";
    NSString *bImg = @"";
    _closeType = index;
    if (_isHuiGou)
    {
        if (_carAry.count > 0)
        {
            _blackView.hidden = NO;
            [_tableview reloadData];
        }
        else
        {
            AddCarViewController *vc = [[AddCarViewController alloc] init];
            WEAKSELF;
            vc.isTixian = YES;
            vc.addBlock = ^(BankModel *model) {
                weakSelf.bankModel = model;
                if ([_bankDic.allKeys containsObject:model.bankId])
                {
                    _bankImgView.image = [UIImage imageNamed:_bankDic[model.bankId]];
                }
                if (model.bankcard.length > 4)
                {
                    NSString *carLastStr = [model.bankcard substringFromIndex:model.bankcard.length-4];
                    _bankLab.text = [NSString stringWithFormat:@"%@ %@ (%@)",model.bankName,model.cardType,carLastStr];
                }
                [weakSelf requestBankCarList];
            };
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
    else
    {
        if (index == 0)
        {
            
            aImg = @"yuand";
            bImg = @"xuankuang";
            
        }
        else if (index == 1)
        {
            bImg = @"yuand";
            aImg = @"xuankuang";
        }
        UIImageView *imageView = (UIImageView *)[_closeView viewWithTag:500];
        imageView.image = [UIImage imageNamed:aImg];
        UIImageView *imageBView = (UIImageView *)[_closeView viewWithTag:501];
        imageBView.image = [UIImage imageNamed:bImg];
    }
}

- (void)creatPayPassWordView
{
    if (!self.payPassView)
    {
        self.payPassView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _payPassView.backgroundColor = RGBA(0, 0, 0, 0.5);
        [sharedDelegate.window addSubview:_payPassView];
        UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(0, 230*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-230*displaywidth)];
        secondView.backgroundColor = RGB(242, 242, 242);
        [_payPassView addSubview:secondView];
        UILabel *titleLabel = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH/2-80*displaywidth, 0, 160*displaywidth, 44*displaywidth) Font:15.0 Text:@"请输入回购密码" Color:RGB(77, 77, 77)];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [secondView addSubview:titleLabel];
        UIButton *contactBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-60*displaywidth, 0, 44*displaywidth, 44*displaywidth) ImageName:@"chacha" Target:self Action:@selector(contactAction) Title:nil Font:13.0];
        contactBtn.backgroundColor = [UIColor clearColor];
        [secondView addSubview:contactBtn];
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 44*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineview.backgroundColor = RGB(210, 210, 210);
        [secondView addSubview:lineview];
        UILabel *moneyLabel = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 55*displaywidth, SCREEN_WIDTH-30*displaywidth, 25*displaywidth) Font:15.0 Text:[NSString stringWithFormat:@"提现金额 %@",_moneyField.text] Color:RGB(77, 77, 77)];
        moneyLabel.textAlignment = NSTextAlignmentCenter;
        [secondView addSubview:moneyLabel];
        self.pasView = [[SYPasswordView alloc] initWithFrame:CGRectMake(15*displaywidth, 90*displaywidth, SCREEN_WIDTH-30*displaywidth, 44*displaywidth)];
        _pasView.delegate = self;
        [secondView addSubview:_pasView];
        UIButton *forgotBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-115*displaywidth, 150*displaywidth, 100*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(FindPassword) Title:@"忘记密码" Font:13.0];
        [forgotBtn setTitleColor:RGB(255, 111, 28) forState:UIControlStateNormal];
        [secondView addSubview:forgotBtn];
    }
    _payPassView.hidden = NO;
    [_pasView.textField becomeFirstResponder];
}

- (void)shuruSuccessValue:(NSString *)value
{
    [self requestPublicKey:value];
}

- (void)requestPublicKey:(NSString *)passWorld
{
    WEAKSELF;
    [MBProgressHUD showHUDAddedTo:sharedDelegate.window animated:YES];
    [HYBaseHandler requestPublicKeyParmers:nil Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             NSString *publicKey = obj[@"data"];
             //测试要加密的数据
             NSString *sourceStr = passWorld;
             //公钥加密
             NSString *encryptStr = [RSA encryptString:sourceStr publicKey:publicKey];
             NSDictionary *dic = @{@"bankCardId":s_str(_bankModel.ID),
                                   @"money":_moneyField.text,
                                   @"password":encryptStr
                                   };
             [HYBaseHandler requestUserWithdrawParmers:dic Success:^(id obj)
              {
                  [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
                  if ([obj server_Getcodecheck])
                  {
                      NSString *day = obj[@"data"][@"withdrawWay"];
                      [LTools showMBProgressWithText:string(@"提交成功，预计", string(day, @"天到账")) addToView:sharedDelegate.window];
                      [weakSelf contactAction];
                      [weakSelf.navigationController popViewControllerAnimated:YES];
                      
                  }
                  else
                  {
                      [self.pasView clearUpPassword];
                      [LTools showMBProgressWithText:obj[@"msg"] addToView:sharedDelegate.window];
                      
                  }
                  
              } failed:^(NSError *error) {
                  [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
                  
              }];
             
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:sharedDelegate.window];
             [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
         }
     } failed:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
     }];
}

//找回密码
- (void)FindPassword
{
    _payPassView.hidden = YES;
    [self.pasView endEditing:YES];
    [self.pasView clearUpPassword];
    BuyBackPasswordViewController *vc = [[BuyBackPasswordViewController alloc] init];
    vc.isPayPass = NO;
    vc.passType = @"5";
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)contactAction
{
    _payPassView.hidden = YES;
    [self.pasView endEditing:YES];
    [self.pasView clearUpPassword];
}

- (void)pushBtnAction
{
    [self.view endEditing:YES];
    if (!_isHuiGou)
    {
        if ([_moneyField.text floatValue] <= 0)
        {
            [LTools showMBProgressWithText:@"请输入充值金额" addToView:self.view];
            return;
        }
        NSDictionary *dic = @{@"money":_moneyField.text,
                              @"clientId":@"4",
                              @"payWay":[NSString stringWithFormat:@"%ld",_closeType+1]
                              };
        WEAKSELF;
        [HYBaseHandler requestRechargeCreatParmers:dic Success:^(id obj) {
            if ([obj server_Getcodecheck])
            {
                NSString *tradeNo = obj[@"data"][@"tradeNo"];
                PayManager *manage = [PayManager sharePayManager];
                [manage startPayRequest:_closeType Pid:tradeNo];
            }
            else
            {
                [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
            }
        } failed:^(NSError *error) {
            
        }];
        
    }
    else
    {
        if (!_bankModel)
        {
            [LTools showMBProgressWithText:@"请选择提现银行卡" addToView:self.view];
            return;
        }
        if (!_isCan)
        {
            [LTools showMBProgressWithText:@"当前积分不足以提现" addToView:self.view];
            return;
        }
        if ([_moneyField.text integerValue] < 100)
        {
            [LTools showMBProgressWithText:@"提现积分需大于100" addToView:self.view];
            return;
        }
        [self creatPayPassWordView];
        
    }
}

- (void)backAction
{
    _blackView.hidden = YES;
}


- (void)requestBankCarList
{
    WEAKSELF;
    [HYBaseHandler requestBankCarListParmers:nil Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             weakSelf.carAry = [BankModel mj_objectArrayWithKeyValuesArray:obj[@"data"]];
             if (weakSelf.carAry.count > 0)
             {
                 dispatch_async(dispatch_get_main_queue(), ^{
                     CGFloat h = (weakSelf.carAry.count+1)*50*displaywidth;
                     if (h > 250*displaywidth)
                     {
                         h = 250*displaywidth;
                     }
                     weakSelf.tableview.frame = CGRectMake(50*displaywidth, SCREEN_HEIGHT/2-h/2-30*displaywidth, SCREEN_WIDTH-100*displaywidth, h);
                     [weakSelf.tableview reloadData];
                 });
             }
             
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
         
     } failed:^(NSError *error) {
         
     }];
}

- (void)requestSystemConfig
{
    WEAKSELF;
    NSString *keyStr = @"recharge_rate";
    if (_isHuiGou) {
        keyStr = @"withdraw_rate,withdraw_server_rate";
    }
    NSDictionary *dic = @{@"keys":keyStr};
    [HYBaseHandler requestSystemConfigParmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            if (!weakSelf.isHuiGou)
            {
                NSString *recharge = obj[@"data"][@"recharge_rate"];
                weakSelf.proportLab.text = string(@"兑换比率 ", recharge);
            }
            else
            {
                NSString *withdraw = obj[@"data"][@"withdraw_rate"];
                NSString *server = obj[@"data"][@"withdraw_server_rate"];
                weakSelf.proportLab.text = string(string(@"兑换比率 ", withdraw), string(@"  手续费率",server));
            }
            
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

//我的积分
- (void)requestUserWallet
{
    WEAKSELF;
    [HYBaseHandler requestUserWalletParmers:nil Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            NSString *twoIntegral = obj[@"data"][@"twoIntegral"];
            if ([twoIntegral integerValue] >= 100)
            {
                weakSelf.nowTxLab.text = [NSString stringWithFormat:@"当前可提现：%@积分",twoIntegral];
                weakSelf.isCan = YES;
            }
            else
            {
                weakSelf.nowTxLab.text = @"当前可提现：当前积分不足以提现";
                weakSelf.isCan = NO;
            }
            
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (_isHuiGou)
    {
        if ([textField.text integerValue] >= 100)
        {
            NSString *str = textField.text;
            NSInteger money = [str integerValue];
            textField.text = [NSString stringWithFormat:@"%ld",money/100*100];
        }
        else
        {
            [LTools showMBProgressWithText:@"提现积分需大于100" addToView:self.view];
        }
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

